package com.yh.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletRequestAttributeEvent;
import javax.servlet.ServletRequestAttributeListener;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionActivationListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * <pre>
 * - 监听器
 * ClassName : com.yh.listener.MyListener
 * &#64;author 湛锋
 * Date : 2020年8月7日 下午5:42:16
 * </pre>
 *
 */
//@WebListener
public class MyListener implements ServletContextListener, HttpSessionListener, ServletRequestListener,
		ServletContextAttributeListener, HttpSessionActivationListener, ServletRequestAttributeListener {

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		// 上下文创建后调用
		// 工程初始化和全局的设置
		ServletContext application = sce.getServletContext();
		System.out.println("工程的上下文对象创建了：" + application);
		application.setAttribute("webName", "xxxyh");
	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		// 上下文销毁前调用
		// 工程全局的销毁和保存工作
		ServletContext application = sce.getServletContext();
		System.out.println("工程的上下文对象销毁了：" + application);
	}

	@Override
	public void sessionCreated(HttpSessionEvent se) {
		// 会话创建
		HttpSession session = se.getSession();
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent se) {
		// 会话销毁
		HttpSession session = se.getSession();
	}

	@Override
	public void requestDestroyed(ServletRequestEvent sre) {
		// 请求的创建
		HttpServletRequest requset = (HttpServletRequest) sre.getServletRequest();
	}

	@Override
	public void requestInitialized(ServletRequestEvent sre) {
		// 请求的销毁
		HttpServletRequest requset = (HttpServletRequest) sre.getServletRequest();
	}

	@Override
	public void attributeAdded(ServletContextAttributeEvent event) {
		// 上下文属性每一次添加时都会调用
		ServletContext application = event.getServletContext();
		String name = event.getName();
		Object value = event.getValue();
	}

	@Override
	public void attributeRemoved(ServletContextAttributeEvent event) {
		// 上下文属性移除时调用
	}

	@Override
	public void attributeReplaced(ServletContextAttributeEvent event) {
		// 上下文属性替换时调用
	}

	@Override
	public void attributeAdded(ServletRequestAttributeEvent srae) {

	}

	@Override
	public void attributeRemoved(ServletRequestAttributeEvent srae) {

	}

	@Override
	public void attributeReplaced(ServletRequestAttributeEvent srae) {

	}

	@Override
	public void sessionWillPassivate(HttpSessionEvent se) {

	}

	@Override
	public void sessionDidActivate(HttpSessionEvent se) {

	}

}
